<template>
  <div class="shareimg">
    <!-- 顶部区域 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <!-- 这里方多个样式，可以通过放置数组的方式  -->
          <a
            :class="['mui-control-item', item.id==0 ? 'mui-active' : '']"
            v-for="item in shareImg"
            :key="item.id" @click="getCardById(item.id)"
          >{{item.title}}</a>
        </div>
      </div>
    </div>
    <!-- 图片列表区域 -->
    <ul>
        <router-link v-for="item in cardList" :key='item.id' class='cardimg' :to="'/home/photoinfo/'
        +item.id" tag='li'
        >
            <img v-lazy="item.img_url">
            <div class='intro'>
                <h3>{{item.topic}}</h3>
                <p class='tit'>
                    {{item.describe}}
                </p>
            </div>
        </router-link>
    </ul>

  </div>
</template>


<script>
// 导入mui
import mui from "./../../assets/js/mui.min.js";
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      shareImg: [], //所有分类的数组列表
      list:[],   //图片列表数组
      cardList:[]    //分类的列表图片
    };
  },
  mounted() {
    // 组件中的dom结构挂载好，会执行该钩子函数
    // 初始化mui
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  created() {
    this.getShare();
    this.getAllShareImgById();

  },

  methods: {
    getShare() {
      this.$http.get("http://localhost:1000/shareImg").then(res => {
        if (res.status == 200) {
          res.body.unshift({ id: "0", title: "全部" });
          this.shareImg = res.body;
        } else {
          Toast("获取数据失败！");
        }
      });
    },
    
    getAllShareImgById(){
        this.$http.get("http://localhost:1000/shareList").then(res=>{
           if (res.status == 200) {
            this.list = res.body;
            this.cardList=this.list;
            } else {
            Toast("获取数据失败！");
         } 
        })
    },
    getCardById(cardId){
        this.cardList=[];
        this.list.forEach(element => {
          if(element.bid==cardId){
              this.cardList.push(element)
          }else if(cardId==0){
               this.cardList.push(element)           
          }
        });
    }
  }
};
</script>


<style lang="scss" scoped>

img[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
ul li.cardimg{
    position: relative;
    list-style: none;
    box-shadow: 0 0 10px grey;
    width: 90%;
    margin: 0 auto;
    height: auto;
    margin-top: 15px;
    font-size: 0;
    border-radius: 5px;
}
ul li.cardimg img{
    width: 100%;
    border-radius: 5px;
    vertical-align: middle;
}
.intro{
    width: 100%;
    padding: 0 10px;
    position: absolute;
    bottom: 0;
    left: 0;
    background: rgba($color: #000, $alpha: 0.4);
    h3{
        font-size: 16px;
    }
    p.tit{
        color: #fff;
        margin-bottom: 0;
    }
}

</style>
